<template>
  <div id="ordersList">
    <h3>订单数据</h3>
    <div class="search">
      <el-select v-model="searchData.type" size="mini">
        <el-option
          v-for="item in options"
          :key="item.value"
          :label="item.label"
          :value="item.value"
        >
        </el-option>
      </el-select>
      <el-input
        v-model="searchData.value"
        placeholder="请输入内容"
        size="mini"
      ></el-input>
    </div>
    <el-table :data="orders" border stripe style="width: 100%">
      <el-table-column prop="_id" label="订单编号"> </el-table-column>
      <el-table-column prop="ordersTime" label="创建时间"> </el-table-column>
      <el-table-column prop="customersId.name" label="订单客户">
      </el-table-column>
      <el-table-column prop="payPhone" label="支付手机"> </el-table-column>
      <el-table-column
        prop="ordersPayState"
        :formatter="PayState"
        label="订单状态"
      ></el-table-column>
      <el-table-column
        prop="ordersState"
        :formatter="State"
        label="理赔状态"
      ></el-table-column>
    </el-table>
    <div class="block">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="pagesData.currentPage"
        :page-sizes="[ 3, 5, 7]"
        :page-size="pagesData.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="pagesData.total"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
import { createNamespacedHelpers } from "vuex";
const { mapActions, mapState, mapMutations } = createNamespacedHelpers(
  "Orders"
);
export default {
  data() {
    return {
      options: [
        {
          value: "ordersTime",
          label: "订单时间",
        }
      ],
      searchData: {
        type: "ordersTime",
        value: "",
      },
      order: [],
    };
  },
  created() {
    this.getOrders(this.searchData);
  },

  computed: {
    ...mapState(["orders", "pagesData"]),
  },

  methods: {
    ...mapActions(["getOrders"]),
    ...mapMutations(["changePageSize", "changeCurrentPage"]),
    PayState(row, column) {
      switch (row.ordersPayState) {
        case 0: {
          return "已支付";
          break;
        }
        case 1: {
          return "未支付";
          break;
        }
        case 2: {
          return "退保中";
          break;
        }
        case 3: {
          return "已退保";
          break;
        }
        case 4: {
          return "退保申请";
          break;
        }
      }
    },

    State(row, column) {
      switch (row.ordersState) {
        case 0: {
          return "未理赔";
          break;
        }
        case 1: {
          return "理赔申请中";
          break;
        }
        case 2: {
          return "理赔中";
          break;
        }
        case 3: {
          return "已理赔";
          break;
        }
      }
    },
    handleSizeChange(val) {
      this.changePageSize(val);
      this.getOrders(this.searchData);
    },

    handleCurrentChange(val) {
      this.changeCurrentPage(val);
      this.getOrders(this.searchData);
    },
  },

  watch: {
    searchData: {
      handler(value) {
        this.changeCurrentPage(1);
        this.getOrders(value);
      },
      deep: true,
    },
  },
};
</script>

<style lang="scss">
#ordersList {
  h3 {
    margin-bottom: 10px;
  }
  .el-button {
    margin: 5px;
  }
  .el-table th,
  .el-table td {
    text-align: center;
    padding: 5px 0;
  }
  .search {
    display: flex;
    align-items: center;
    margin-bottom: 5px;
    .el-select {
      width: 100px;
      margin-right: 5px;
      .el-input {
        width: 100%;
      }
    }
    .el-input {
      width: 30%;
    }
  }
}
</style>